package com.top4create.service.impl;

import java.util.List;

import javax.jws.WebService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.orm.jpa.JpaSystemException;
import org.springframework.security.authentication.encoding.PasswordEncoder;
import org.springframework.stereotype.Service;

import com.top4create.dao.CompanyDao;
import com.top4create.dao.GenericDao;
import com.top4create.model.Company;
import com.top4create.service.CompanyManager;
import com.top4create.service.CompanyService;
import com.top4create.webapp.util.PageListUtil;

@Service("companyManager")
@WebService(serviceName = "CompanyService", endpointInterface = "com.top4create.service.CompanyService")
public class CompanyManagerImpl extends GenericManagerImpl<Company, Long>
		implements CompanyManager, CompanyService {
	private CompanyDao companyDao;

	public CompanyManagerImpl(GenericDao<Company, Long> genericDao) {
		super(genericDao);
		// TODO Auto-generated constructor stub
	}

	@Autowired
	public void setCompanyDao(CompanyDao companyDao) {
		this.dao = companyDao;
		this.companyDao = companyDao;
	}

	/**
	 * {@inheritDoc}
	 */
	public Company getCompany(String CompanyId) {
		return companyDao.get(new Long(CompanyId));
	}

	/**
	 * {@inheritDoc}
	 */
	public List<Company> getCompanys() {
		return companyDao.getListForPage("1=1", 0, 3);
	}

	/**
	 * {@inheritDoc}
	 */
	public Company saveCompany(Company Company) {
		return Company;
	}

	/**
	 * {@inheritDoc}
	 */
	public void removeCompany(String CompanyId) {
		log.debug("removing Company: " + CompanyId);
		companyDao.remove(new Long(CompanyId));
	}

	/**
	 * {@inheritDoc}
	 */
	public List<Company> search(String searchTerm) {
		return super.search(searchTerm, Company.class);
	}

	public PageListUtil getCompanys(int pageNumber, int pageSize, String where) {
		where = where == null ? "1=1" : where;
		PageListUtil pageList = new PageListUtil();
		// 设置当前页数
		pageList.setPageNumber(pageNumber);
		// 设置当前页列表
		pageList.setList(companyDao.getListForPage(where, (pageNumber - 1)
				* pageSize, pageSize));
		// 设置page size
		pageList.setObjectsPerPage(pageSize);
		// 设置总页数
		pageList.setFullListSize(companyDao.getTotalCount(where));
		// TODO Auto-generated method stub
		return pageList;
	}
	
	public String getCompanysJson(int pageNumber, int pageSize, String where) {
		
		return getCompanys(pageNumber,pageSize,where).toString();
	}

	public PageListUtil getCompanys(int pageNumber, String pageSize,
			String where) {
		// TODO Auto-generated method stub
		return null;
	}
}
